/**
 * @BaseResultCode.java  COPYRIGHT xiaojian
 * 
 * Created on 2019年4月10日 下午5:07:16
 */
package xj.toolkit.base;

import org.apache.commons.lang3.builder.ToStringBuilder;

import com.google.common.base.Preconditions;

/**
 * 定义一个通用的错误代码，业务系统可以基于这个继续定义自己的通用错误代码。
 * 
 * @author <a href="mailto:cxj2000@gmail.com">xiaojian.cao</a>
 *
 */
public class BaseResultCode implements ResultCode {

	private static final long serialVersionUID = 6447149331679368369L;

	public static final ResultCode OK = new BaseResultCode(0, "OK");
	public static final ResultCode CLIENT_ARGU_ERROR = new BaseResultCode(10, "客户端参数错误");
	public static final ResultCode SERVER_ERROR = new BaseResultCode(11, "服务器错误");
	public static final ResultCode OPERATION_TIMEOUT = new BaseResultCode(12, "操作超时");

	protected int code;
	protected String resultDesc = null;

	/**
	 * 空构建函数
	 */
	public BaseResultCode() {
	}

	public BaseResultCode(int code, String desc) {
		this.code = code;
		this.resultDesc = desc;
	}

	/**
	 * 
	 * @param resultCode
	 */
	public BaseResultCode(ResultCode resultCode) {
		Preconditions.checkArgument(resultCode != null);

		this.code = resultCode.getResultCode();
		this.resultDesc = resultCode.getDescription();
	}

	public String getDescription() {
		return resultDesc;
	}

	public int getResultCode() {
		return code;
	}

	/**
	 * @param code
	 *            the code to set
	 */
	public ResultCode setResultCode(int code) {
		this.code = code;
		return this;
	}

	/**
	 * @param resultDesc
	 *            the resultDesc to set
	 */
	public ResultCode setDescription(String resultDesc) {
		this.resultDesc = resultDesc;
		return this;
	}

	public String toString() {
		return ToStringBuilder.reflectionToString(this);
	}

}
